test visualizazion of GreenLand masks

link <- "/data/Dagobah/greengrass/grassland_ger/01_CTM_GL_mask_17-19/GL_mask_2017-2019.tif"

mask_GL <- terra::rast(link)

plot(mask_GL)

test vis for tsi output

plot raw images

link <- "/data/Dagobah/greengrass/schnesha/03_RBF_interpolation_LND_1982-2021/X0060_Y0040/1984-2021_001-365_HL_TSA_LNDLG_NDV_TSI.tif"

tsi_raw <- rast(link)

setMinMax(tsi_raw) # set MinMax for spatRaster

# create filter out all layers that dont contain any values
tsi_na_index <- minmax(tsi_raw) |> 
  as.data.frame() |> 
  slice(1) |> 
  pivot_longer(everything()) |> 
  mutate(id = row_number()) |> 
  na.omit()

# convert into index vector
tsi_na_index <- as.vector(tsi_na_index$id)

# subset tsi object with only layers containing values
tsi <- tsi_raw[[tsi_na_index]]

#rasterVis::levelplot(tsi[[c(24)]], par.settings = viridisTheme)
#rasterVis::levelplot(tsi[[c(1,4,24,25:35)]], par.settings = viridisTheme)
plot(tsi[[c(1:10)]], legend=F, col = viridis(n=100,option="D"),
     range=c(0,10000)
    )

gif image creation

for (i in c(1:100
            #length(names(tsi))
                     )) {
  
   # Step 1: Call the pdf command to start the plot
  png(file = paste0("/data/Dagobah/greengrass/schnesha/03_RBF_interpolation_LND_1982-2021/ts_gif/day_16_sigma_8_16_32/plot_", i, ".png"), width = 265, height = 125, units='mm', res = 300) #,   # The directory you want to save the file in
   # width = 12, # The width of the plot in inches
    #height = 12) # The height of the plot in inches
plot(tsi[[i]], legend=T, col = viridis(n=100,option="D"),
     range=c(0,10000),
    plg=list( title = paste(as.Date(names(tsi[[i]]), format="%Y%m%d")), title.cex=1.25)
)


# Step 3: Run dev.off() to create the file
dev.off()
}
knitr::include_graphics("/data/Dagobah/greengrass/schnesha/03_RBF_interpolation_LND_1982-2021/ts_gif/day_16_sigma_8_16_32/ts_16_8_16_32.gif")

spectra visualization

data manipulation and subsample creation

tsi_df <- terra::as.data.frame(tsi[[c(600:834)]], xy = TRUE, na.rm=T) |> 
  slice_sample(n=50)

tsi_df_long <- tsi_df |> 
  pivot_longer(cols = c(3:ncol(tsi_df)), names_to = "timestamp") |> 
  mutate(xy= paste0(x,"_",y)) |> 
  mutate(date = as.Date(timestamp, format="%Y%m%d"),
         year = lubridate::year(date))

plot faceted time series

ggplot(tsi_df_long, aes(date, value, group=xy, color=xy)) +
  geom_line() +
  theme_classic() +
  scale_colour_viridis_d(option = "D") +
  scale_x_date(date_breaks = "1 month", date_labels = "%m")+
  theme(axis.text.x = element_text(angle = 45,  hjust=1),
        legend.position="none") +
  facet_wrap(~year, scales = "free_x")

plot time series with formatted dates

ggplot(tsi_df_long, aes(date, value, group=xy, color=xy)) +
  geom_line() +
  theme_classic() +
  scale_colour_viridis_d(option = "D") +
  scale_x_date(date_breaks = "1 month", date_labels = "%m-%y")+
  theme(axis.text.x = element_text(angle = 45,  hjust=1),
        legend.position="none")

ggplot(tsi_df_long, aes(date, value)) +
  geom_smooth() +
  theme_classic() +
    scale_x_date(date_breaks = "1 year", date_labels = "%d-%m-%y")+
  theme(axis.text.x = element_text(angle = 45 ,  hjust=1)) 
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

ggplot(tsi_df_long, aes(date, value, group = timestamp)) +
  geom_boxplot() +
  theme_classic() +
  scale_x_date( date_labels = "%d-%m-%y")+
  theme(axis.text.x = element_text(angle = 45, hjust=1)) 

ggplot + tidyterra vis option (nice but runs slow)

ggplot() +
  geom_spatraster(data = tsi[[c(4:8)]]) +
  facet_wrap(~lyr, ncol = 2) +
  scale_fill_whitebox_c(
    palette = "viridi",
   # labels = scales::label_number(suffix = "ยบ")
  ) +
  labs(fill = "NDVI") +
  theme_classic()